### Zero Sum
library(readstata13)

study.1 <- read.dta13("~/Dropbox/Muslim_Inclusion_Policy_Survey/Zerosum/Study1.dta")
study.2 <- read.dta13("~/Dropbox/Muslim_Inclusion_Policy_Survey/Zerosum/Study2.dta")

# Ns
table(study.1$Q15_meal)
table(study.1$Q16_holiday)

table(study.2$treat_schnitzel)
table(study.2$treat_rel_holiday_1)
table(study.2$treat_rel_holiday_2)


# Balance Checks
study.1$female <- ifelse(study.1$Q65==2, 1, 0)
study.1$age<- ifelse(study.1$Q67==-99 | study.1$Q67>100, NA, study.1$Q67)
study.1$abi <- ifelse(study.1$Q68==-99, NA, study.1$Q68)
study.1$abi <- ifelse(study.1$abi==4, 1, 0)
study.1$imcp <-  (study.1$Q17_1 + study.1$Q17_2 + study.1$Q17_3 + study.1$Q17_4)/4 
study.1$immig <-  (study.1$Q40 + study.1$Q41 + study.1$Q42)/3 
study.1$leftright <- study.1$Q23
study.1$religious <- study.1$Q38
study.1$christid <-  (study.1$Q28_1 + study.1$Q28_2 + study.1$Q28_3 + study.1$Q28_4 + study.1$Q28_5)/5 

# Table A9

round(aggregate(study.1$female, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$age, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$abi, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$imcp, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$immig, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$leftright, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$religious, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x
round(aggregate(study.1$christid, by=list(study.1$Q15_meal), mean, na.rm=T), 2)$x


# Table A10

round(aggregate(study.1$female, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$age, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$abi, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$imcp, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$immig, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$leftright, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$religious, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x
round(aggregate(study.1$christid, by=list(study.1$Q16_holiday), mean, na.rm=T), 2)$x

study.2$female <- ifelse(study.2$gender=="Weiblich", 1, 0)
study.2$age <- 2022-study.2$age
study.2$abi <- ifelse(study.2$education=="Abitur, allgemeine oder fachgebundene Hochschulreife bzw. Erweiterte Oberschule der ehem. DDR mit Abschluss 12. Klasse", 1, 0)
study.2$left_right <- ifelse(study.2$left_right=="NA", NA, study.2$left_right)
study.2$left_right <- as.numeric(study.2$left_right)
study.2$impc_1 <- ifelse(study.2$impc_1=="NA" | study.2$impc_1=="Weiß nicht", NA, study.2$impc_1)
study.2$impc_2 <- ifelse(study.2$impc_2=="NA" | study.2$impc_2=="Weiß nicht", NA, study.2$impc_2)
study.2$impc_3 <- ifelse(study.2$impc_3=="NA" | study.2$impc_3=="Weiß nicht", NA, study.2$impc_3)
study.2$impc_4 <- ifelse(study.2$impc_4=="NA" | study.2$impc_4=="Weiß nicht", NA, study.2$impc_4)
study.2$imcp_1 <- ordered(as.factor(study.2$impc_1), levels=c("stimme überhaupt nicht zu", "Stimme eher nicht zu", "Weder noch", "Stimme eher zu", "Stimme voll und ganz zu"))
study.2$imcp_2 <- ordered(as.factor(study.2$impc_2), levels=c("stimme überhaupt nicht zu", "Stimme eher nicht zu", "Weder noch", "Stimme eher zu", "Stimme voll und ganz zu"))
study.2$imcp_3 <- ordered(as.factor(study.2$impc_3), levels=c("stimme überhaupt nicht zu", "Stimme eher nicht zu", "Weder noch", "Stimme eher zu", "Stimme voll und ganz zu"))
study.2$imcp_4 <- ordered(as.factor(study.2$impc_4), levels=c("stimme überhaupt nicht zu", "Stimme eher nicht zu", "Weder noch", "Stimme eher zu", "Stimme voll und ganz zu"))
study.2$imcp_1 <- as.numeric(study.2$imcp_1)
study.2$imcp_2 <- as.numeric(study.2$imcp_2)
study.2$imcp_3 <- as.numeric(study.2$imcp_3)
study.2$imcp_4 <- as.numeric(study.2$imcp_4)
study.2$imcp <- (study.2$imcp_1 + study.2$imcp_2 + study.2$imcp_3 + study.2$imcp_4)/4

study.2$culturalliberalismconservatism_d <- study.2$culturalliberalismconservatism_d-1

study.2$treat_schnitzel_n <- as.numeric(as.factor(study.2$treat_schnitzel))
study.2$treat_schnitzel_n <- ifelse(study.2$treat_schnitzel_n==1 | 
                                      study.2$treat_schnitzel_n==4 | 
                                      study.2$treat_schnitzel_n==5 | 
                                      study.2$treat_schnitzel_n==7 | 
                                      study.2$treat_schnitzel_n==9, NA, study.2$treat_schnitzel_n
)


# Table A11

round(aggregate(study.2$female, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$age, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$abi, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$imcp, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$left_right, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$culturalliberalismconservatism_d, by=list(study.2$treat_schnitzel_n), mean, na.rm=T), 2)$x

study.2$treat_rel_holiday_2_n <- as.numeric(as.factor(study.2$treat_rel_holiday_2))
study.2$treat_rel_holiday_2_n <- ifelse(study.2$treat_rel_holiday_2_n==3, 2, 1)

study.2$treat_rel_holiday_1_n <- as.numeric(as.factor(study.2$treat_rel_holiday_1))

# Table A12

round(aggregate(study.2$female, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$age, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$abi, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$imcp, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$left_right, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
round(aggregate(study.2$culturalliberalismconservatism_d, by=list(study.2$treat_rel_holiday_1_n, study.2$treat_rel_holiday_2_n), mean, na.rm=T), 2)$x
